package com.lm.sharding.config;

import org.apache.shardingsphere.driver.api.yaml.YamlShardingSphereDataSourceFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.core.io.ClassPathResource;

import javax.sql.DataSource;
import java.io.File;
import java.io.IOException;
import java.sql.SQLException;

//@Configuration
public class DataSourceConfig {

    @Bean
    public DataSource shardingSphereDataSource() throws SQLException, IOException {
        // 假设你使用 YAML 配置或 Properties 构造 ShardingSphereDataSource
        String modelPath = new ClassPathResource("shardingsphere-config.yml").getFile().getAbsolutePath();
        File yamlFile = new File(modelPath);
        return YamlShardingSphereDataSourceFactory.createDataSource(yamlFile);
    }
}
